/***************************************************************
Copyright Statement:

This software/firmware and related documentation (EcoNet Software) 
are protected under relevant copyright laws. The information contained herein 
is confidential and proprietary to EcoNet (HK) Limited (EcoNet) and/or 
its licensors. Without the prior written permission of EcoNet and/or its licensors, 
any reproduction, modification, use or disclosure of EcoNet Software, and 
information contained herein, in whole or in part, shall be strictly prohibited.

EcoNet (HK) Limited  EcoNet. ALL RIGHTS RESERVED.

BY OPENING OR USING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY 
ACKNOWLEDGES AND AGREES THAT THE SOFTWARE/FIRMWARE AND ITS 
DOCUMENTATIONS (ECONET SOFTWARE) RECEIVED FROM ECONET 
AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER ON AN AS IS 
BASIS ONLY. ECONET EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES, 
WHETHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED 
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, 
OR NON-INFRINGEMENT. NOR DOES ECONET PROVIDE ANY WARRANTY 
WHATSOEVER WITH RESPECT TO THE SOFTWARE OF ANY THIRD PARTIES WHICH 
MAY BE USED BY, INCORPORATED IN, OR SUPPLIED WITH THE ECONET SOFTWARE. 
RECEIVER AGREES TO LOOK ONLY TO SUCH THIRD PARTIES FOR ANY AND ALL 
WARRANTY CLAIMS RELATING THERETO. RECEIVER EXPRESSLY ACKNOWLEDGES 
THAT IT IS RECEIVERS SOLE RESPONSIBILITY TO OBTAIN FROM ANY THIRD 
PARTY ALL PROPER LICENSES CONTAINED IN ECONET SOFTWARE.

ECONET SHALL NOT BE RESPONSIBLE FOR ANY ECONET SOFTWARE RELEASES 
MADE TO RECEIVERS SPECIFICATION OR CONFORMING TO A PARTICULAR 
STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND 
ECONET'S ENTIRE AND CUMULATIVE LIABILITY WITH RESPECT TO THE ECONET 
SOFTWARE RELEASED HEREUNDER SHALL BE, AT ECONET'S SOLE OPTION, TO 
REVISE OR REPLACE THE ECONET SOFTWARE AT ISSUE OR REFUND ANY SOFTWARE 
LICENSE FEES OR SERVICE CHARGES PAID BY RECEIVER TO ECONET FOR SUCH 
ECONET SOFTWARE.
***************************************************************/
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include "omci_lib/omci_lib_internal.h"

static int do_get_sn_passwd(int argc, char *argv[], void *p);
static int do_get_omci_dbg_level(int argc, char *argv[], void *p);
static int do_get_lan_debug(int argc, char *argv[], void *p);
static int do_get_enhanced_psk(int argc, char *argv[], void *p);
static int do_get_onu_version(int argc, char *argv[], void *p);
static int do_get_vendor_id(int argc, char *argv[], void *p);
static int do_get_equipment_id(int argc, char *argv[], void *p);
static int do_get_operator_id_cap(int argc, char *argv[], void *p);
static int do_get_operator_id_auth(int argc, char *argv[], void *p);
static int do_get_loid(int argc, char *argv[], void *p);
static int do_get_loid_password(int argc, char *argv[], void *p);
static int do_get_link_mode(int argc, char *argv[], void *p);
static int do_get_vendor_pro_code(int argc, char *argv[], void *p);
static int do_get_omcc_version(int argc, char *argv[], void *p);
static int do_get_tm_option(int argc, char *argv[], void *p);
static int do_get_survival_time(int argc, char *argv[], void *p);
static int do_get_extended_tclayer(int argc, char *argv[], void *p);
static int do_get_security_cap(int argc, char *argv[], void *p);
static int do_get_total_ts_num(int argc, char *argv[], void *p);
static int do_get_total_pq_num(int argc, char *argv[], void *p);
static int do_get_total_gemport_num(int argc, char *argv[], void *p);
static int do_get_connectivity_cap(int argc, char *argv[], void *p);
static int do_get_qos_conf_flex(int argc, char *argv[], void *p);
static int do_get_voip_by_tr069(int argc, char *argv[], void *p);
static int do_get_spec_version(int argc, char *argv[], void *p);
static int do_get_onu_power_ctrl(int argc, char *argv[], void *p);
static int do_get_auth_status(int argc, char *argv[], void *p);
static int do_get_sr_indication(int argc, char *argv[], void *p);
static int do_get_total_tcont_num(int argc, char *argv[], void *p);
static int do_get_gem_block_length(int argc, char *argv[], void *p);
static int do_get_onu_response_time(int argc, char *argv[], void *p);
static int do_get_con_req_port(int argc, char *argv[], void *p);
static int do_get_max_ports_list(int argc, char *argv[], void *p);
static int do_get_voip_sep_en(int argc,char * argv [ ],void * p);

static int do_set_sn(int argc, char *argv[], void *p);
static int do_set_passwd_ascii(int argc, char *argv[], void *p);
static int do_set_passwd_hex(int argc, char *argv[], void *p);
static int do_set_omci_dbg_level(int argc, char *argv[], void *p);
static int do_set_lan_debug(int argc, char *argv[], void *p);
static int do_set_enhanced_psk(int argc, char *argv[], void *p);
static int do_set_onu_version(int argc, char *argv[], void *p);
static int do_set_vendor_id(int argc, char *argv[], void *p);
static int do_set_equipment_id(int argc, char *argv[], void *p);
static int do_set_operator_id_cap(int argc, char *argv[], void *p);
static int do_set_operator_id_auth(int argc, char *argv[], void *p);
static int do_set_loid(int argc, char *argv[], void *p);
static int do_set_loid_password(int argc, char *argv[], void *p);
static int do_set_link_mode(int argc, char *argv[], void *p);
static int do_set_vendor_pro_code(int argc, char *argv[], void *p);
static int do_set_omcc_version(int argc, char *argv[], void *p);
static int do_set_tm_option(int argc, char *argv[], void *p);
static int do_set_survival_time(int argc, char *argv[], void *p);
static int do_set_extended_tclayer(int argc, char *argv[], void *p);
static int do_set_security_cap(int argc, char *argv[], void *p);
static int do_set_total_ts_num(int argc, char *argv[], void *p);
static int do_set_total_pq_num(int argc, char *argv[], void *p);
static int do_set_total_gemport_num(int argc, char *argv[], void *p);
static int do_set_connectivity_cap(int argc, char *argv[], void *p);
static int do_set_qos_conf_flex(int argc, char *argv[], void *p);
static int do_set_voip_by_tr069(int argc, char *argv[], void *p);
static int do_set_spec_version(int argc, char *argv[], void *p);
static int do_set_onu_power_ctrl(int argc, char *argv[], void *p);
static int do_set_auth_status(int argc, char *argv[], void *p);
static int do_set_sr_indication(int argc, char *argv[], void *p);
static int do_set_total_tcont_num(int argc, char *argv[], void *p);
static int do_set_gem_block_length(int argc, char *argv[], void *p);
static int do_set_onu_response_time(int argc, char *argv[], void *p);
static int do_set_con_req_port(int argc, char *argv[], void *p);
static int do_set_max_ports_list(int argc, char *argv[], void *p);
static int do_set_voip_sep_en(int argc, char *argv[], void *p);
static int do_get_pon_trap_thread(int argc, char *argv[], void *p);
static int do_set_pon_trap_thread(int argc, char *argv[], void *p);


#define END_OF_STRING 1/*Using for '/0' of string when print as '%s'!!*/


typedef struct {
    char *name;
    int (*func)(int argc,char *argv[],void *p);
    int flags;
    int argcmin;
    char *argc_errmsg;
} cmds_t;

static int api_lib_help(int argc, char* argv[], void *p)
{
	const cmds_t *cmdp;
	
	printf("Usage:\n");
	for(cmdp = (const cmds_t *)p; cmdp->name != NULL; cmdp++ ) {
		printf("[%s][%s][%d]%s: %s\n",__FILE__,__FUNCTION__, __LINE__, cmdp->name, cmdp->argc_errmsg);
	}

	return 0;
}

/* Call a subcommand based on the first token in an already-parsed line */
static int subcmd	(const cmds_t tab[], int argc, char *argv[], void *p)
{
	register const cmds_t *cmdp;
	int found = 0;
	int i;

	/* Strip off first token and pass rest of line to subcommand */
	if (argc < 2) {
		if (argc < 1)
			printf("[%s][%s][%d]SUBCMD - Don't know what to do?\n",__FILE__,__FUNCTION__, __LINE__);
		else
			goto print_out_cmds;
		return -1;
	}
	argc--;
	argv++;
	for(cmdp = tab;cmdp->name != NULL;cmdp++){
		if(strncmp(argv[0],cmdp->name,strlen(argv[0])) == 0){
			found = 1;
			break;
		}
	}
	if(!found){
		char buf[102];

print_out_cmds:
		printf("valid subcommands:\n");
		memset(buf,' ',sizeof(buf));
		buf[100] = '\n';
		buf[101] = '\0';
		for(i=0,cmdp = tab;cmdp->name != NULL;cmdp++){
			if(strlen(cmdp->name) < 25)
				strncpy(&buf[i*25], cmdp->name, strlen(cmdp->name));
			else
				strncpy(&buf[i*25], cmdp->name, 24);
			
			if(i == 3){
				printf("%s",buf);
				memset(buf,' ',sizeof(buf));
				buf[100] = '\n';
				buf[101] = '\0';
			}
			i = (i+1)%4;
		}
		if(i != 0)
			printf("%s",buf);
		return -1;
	}
	if(argc <= cmdp->argcmin){
		if(cmdp->argc_errmsg != NULL)
			printf("Usage: %s\n",cmdp->argc_errmsg);
		return -1;
	}
	if(cmdp->func == NULL) 
		return 0;
	
	return (*cmdp->func)(argc,argv,p);
}



static const cmds_t gpon_get_shareM_cmd[] = {
    {"sn",					do_get_sn_passwd,			0,	  0,	"Get the GPON sn from shared memory"},
    {"omciDbgLevel",  		do_get_omci_dbg_level,      0,    0,    "get omci_dbg_level"},
    {"lanDbg",    			do_get_lan_debug,     		0,    0,    "get lan_dbg"}, 
    {"enhancedPsk",    		do_get_enhanced_psk,     	0,    0,    "get enhanced_psk"}, 
    {"onuVersion",    		do_get_onu_version,     	0,    0,    "get onu_version"}, 
    {"vendorId",    		do_get_vendor_id,      		0,    0,    "get vendor_id"}, 
    {"equipmentId",    		do_get_equipment_id,     	0,    0,    "get equipment_id"}, 
    {"opIdCap",    			do_get_operator_id_cap,     0,    0,    "get operator_id_cap"}, 
    {"opIdAuth",    		do_get_operator_id_auth,    0,    0,    "get operator_id_auth"}, 
    {"loid",    			do_get_loid,      			0,    0,    "get loid"},
    {"loidPasswd",   		do_get_loid_password,       0,    0,    "get loid_password"}, 
    {"linkMode",    		do_get_link_mode,       	0,    0,    "get link_mode"},
    {"vendorProCode",    	do_get_vendor_pro_code,     0,    0,    "get vendor_pro_code"},
    {"omccVersion",    		do_get_omcc_version,        0,    0,    "get omcc_version"}, 
    {"tmOption",    		do_get_tm_option,      		0,    0,    "get tm_option"}, 
    {"survivalTime",    	do_get_survival_time,       0,    0,    "get survival_time"}, 
    {"extTcLayer",    		do_get_extended_tclayer,    0,    0,    "get extended_tcLayer"}, 
    {"securityCap",    		do_get_security_cap,        0,    0,    "get security_cap"}, 
    {"totalTsNum",    		do_get_total_ts_num,        0,    0,    "get total_ts_num"}, 
    {"totalPqNum",    		do_get_total_pq_num,        0,    0,    "get total_pq_num"}, 
    {"totalGemNum",    		do_get_total_gemport_num,   0,    0,    "get total_gemport_num"}, 
    {"connectcap",    		do_get_connectivity_cap,    0,    0,    "get connectivity_cap"}, 
    {"qosConfFlex",    		do_get_qos_conf_flex,       0,    0,    "get qos_conf_flex"}, 
    {"voipByTr069",    		do_get_voip_by_tr069,       0,    0,    "get voip_by_tr069"}, 
    {"specVer",    			do_get_spec_version,        0,    0,    "get spec_version"}, 
    {"onuPowerCtr",    		do_get_onu_power_ctrl,      0,    0,    "get onu_power_ctr"}, 
    {"authStat",    		do_get_auth_status,         0,    0,    "get auth_status"}, 
    {"srInd",   			do_get_sr_indication,       0,    0,    "get sr_indication"}, 
    {"totalTcontNum",   	do_get_total_tcont_num,     0,    0,    "get total_tcont_num"}, 
    {"gemBlockLen",   		do_get_gem_block_length,    0,    0,    "get gem_block_length"}, 
    {"onuRespTime",   	 	do_get_onu_response_time,   0,    0,    "get onu_response_time"}, 
    {"conReqPort",    		do_get_con_req_port,      	0,    0,    "get con_req_port"}, 
    {"maxPortsList",    	do_get_max_ports_list,      0,    0,    "get max_ports_list"},
    {"voip_sep_en",         do_get_voip_sep_en,         0,    0,    "get voip sep enable flag"},
	{"pon_trap_thread",     do_get_pon_trap_thread,     0,    0,    "get pon trap thread status"},
};


static const cmds_t gpon_set_shareM_cmd[] = {
    {"sn",					do_set_sn,					0,	  1,	"Set the GPON sn <ABCD12345678>"},
	{"passwdAscii",		    do_set_passwd_ascii,		0,	  1,	"Set GPON password <0~10 ASCII words>"},
	{"passwdHex",			do_set_passwd_hex,			0,	  1,	"Set GPON password <0~20 hexadecimal>"},
    {"omciDbgLevel",		do_set_omci_dbg_level,		0,	  1,	"Set OMCI Debug Level <0~4 Level Value>"},
    {"lanDbg",    			do_set_lan_debug,      		0,    1,    "set lan_dbg <0 or 1: disable or enable>"}, 
    {"enhancedPsk",   		do_set_enhanced_psk,     	0,    1,    "set enhanced_psk <one string with 16 values: %02X,%02X,...,%02X"}, 
    {"onuVersion",    		do_set_onu_version,      	0,    1,    "set onu_version <as this: RP0201>"}, 
    {"vendorId",    		do_set_vendor_id,      		0,    1,    "set vendor_id <as this: MTKG>"}, 
    {"equipmentId",   		do_set_equipment_id,      	0,    1,    "set equipment_id <as this: KE2.119.241R2B>"}, 
    {"opIdCap",    	 		do_set_operator_id_cap,     0,    1,    "set operator_id_cap <as this: CTC>"}, 
    {"opIdAuth",      		do_set_operator_id_auth,    0,    1,    "set operator_id_auth <as this: CTC>"}, 
    {"loid",    			do_set_loid,      			0,    1,    "set loid <as this: mtk1111>"}, 
    {"loidPasswd",   		do_set_loid_password,       0,    1,    "set loid_password"}, 
	{"linkMode",    		do_set_link_mode,	  		0,	  1,	  "set link_mode<0: auto mode; 1:gpon mode; 2:epon mode>"}, 
	{"vendorProCode", 		do_set_vendor_pro_code,	    0,	  1,    "set vendor_pro_code <uint16>"}, 
	{"omccVersion",   		do_set_omcc_version, 	 	0,    1,	 "set omcc_version <hex uint8>"}, 
    {"tmOption",    		do_set_tm_option,      		0,    1,    "set tm_option <uint8>"}, 
    {"survivalTime",  		do_set_survival_time,       0,    1,    "set survival_time <uint8>"}, 
    {"extTcLayer",      	do_set_extended_tclayer,    0,    1,    "set extended_tcLayer <uint8>"}, 
    {"securityCap",   		do_set_security_cap,      	0,    1,    "set security_cap <hex uint8>"}, 
    {"totalTsNum",    		do_set_total_ts_num,      	0,    1,    "set total_ts_num <uint8>"}, 
    {"totalPqNum",    		do_set_total_pq_num,      	0,    1,    "set total_pq_num <uint16>"}, 
    {"totalGemNum",     	do_set_total_gemport_num,   0,    1,    "set total_gemport_num <uint16>"}, 
    {"connectcap",      	do_set_connectivity_cap,    0,    1,    "set connectivity_cap <hex uint16>"}, 
    {"qosConfFlex",   		do_set_qos_conf_flex,      	0,    1,    "set qos_conf_flex <hex uint16>"}, 
    {"voipByTr069",   		do_set_voip_by_tr069,      	0,    1,    "set voip_by_tr069 <int8>"}, 
    {"specVer",    			do_set_spec_version,      	0,    1,    "set spec_version <uint8>"}, 
    {"onuPowerCtr",   		do_set_onu_power_ctrl,      0,    1,    "set onu_power_ctr <uint8>"}, 
    {"authStat",    		do_set_auth_status,      	0,    1,    "set auth_status <uint8>"}, 
    {"srInd",   			do_set_sr_indication,       0,    1,    "set sr_indication <uint8>"}, 
    {"totalTcontNum",   	do_set_total_tcont_num,     0,    1,    "set total_tcont_num <uint16>"}, 
    {"gemBlockLen",     	do_set_gem_block_length,    0,    1,    "set gem_block_length <uint16>"}, 
    {"onuRespTime",     	do_set_onu_response_time,   0,    1,    "set onu_response_time <uint16>"}, 
    {"conReqPort",    		do_set_con_req_port,        0,    1,    "set con_req_port <uint16>"}, 
    {"maxPortsList",  		do_set_max_ports_list,      0,    2,    "set max_ports_list <Para1:maxportnum, para2:portID (%d,%d,%d,....,%d)>"}, 
    {"voip_sep_en",         do_set_voip_sep_en,         0,    1,    "get voip sep enable flag <uint8>"},
	{"pon_trap_thread",     do_set_pon_trap_thread,     0,    1,    "set pon trap thread status"},
};

static int do_set_omci_cmd(int argc, char* argv[], void *p)
{
    return subcmd(gpon_set_shareM_cmd, argc, argv, (void*)gpon_set_shareM_cmd);
}

static int do_get_omci_cmd(int argc, char* argv[], void *p)
{
    return subcmd(gpon_get_shareM_cmd, argc, argv, (void*)gpon_get_shareM_cmd);
}

static const cmds_t omcicfg_root_command[] = {
/*	name,		func, 			flags,	argcmin,	argc_errmsg */
	{"set",	do_set_omci_cmd,			0,		1,			"set omci cfg attribute"},
	{"get",	do_get_omci_cmd,			0,		1,			"get omci cfg attribute"},
	/* Cmd should be added before this line!  */
	{"help",	api_lib_help,	0,		0,			"Show omci cfg usage."},
	{NULL, NULL, 0, 0, NULL}
};


int main(int argc, char **argv)
{	
    return subcmd(omcicfg_root_command, argc, argv, (void*)omcicfg_root_command);
}


/******************************************************************************
 Descriptor:	It's used to get gpon sn.
 Input Args:	see gponmgr_get_command.
 Ret Value:	none.
******************************************************************************/
static int do_get_sn_passwd(int argc, char *argv[], void *p)
{
	char buffer[20] = {0};

	omci_lib_get_sn_mem(buffer,sizeof(buffer));
	printf("ONU SN: %s\n",buffer) ;
	omci_lib_get_passwd_mem(buffer,sizeof(buffer));
	printf("ONU Password: %s\n",buffer) ;

	return 0;
}

/******************************************************************************
 Descriptor:	test get dbg_level
 Input Args:	see gponmgr_root_command.
 Ret Value:	    FAIL:-1.
******************************************************************************/
static int do_get_omci_dbg_level(int argc, char *argv[], void *p)
{
	unsigned char DebugLevel;

	if(0!=omci_lib_get_omci_dbg_level(&DebugLevel)){
		printf("call api error\n");
		return -1;
	}
	printf("dbg_level = %d\n",DebugLevel);
    return 0;
}

/******************************************************************************
 Descriptor:	test get LanDebug
 Input Args:	see gponmgr_root_command.
 Ret Value:	    FAIL:-1.
******************************************************************************/
static int do_get_lan_debug(int argc,char * argv [ ],void * p)
{
	unsigned char LanDebug;

	if(0!=omci_lib_get_lan_debug(&LanDebug)){
		printf("call api error\n");
		return -1;
	}
	printf("LanDebug = %d\n",LanDebug);
    return 0;
}

/******************************************************************************
 Descriptor:	test get enhanced_bsk
 Input Args:	see gponmgr_root_command.
 Ret Value:	    FAIL:-1.
******************************************************************************/
static int do_get_enhanced_psk(int argc,char * argv [ ],void * p)
{
	unsigned char enhanced_bsk[PRESHARED_KEY_LEN];
	int i;

	if(0!=omci_lib_get_enhanced_psk(enhanced_bsk,sizeof(enhanced_bsk))){
		printf("call api error\n");
		return -1;
	}
	printf("enhancedBSk = ");
	for(i = 0; i < sizeof(enhanced_bsk); i++){
		printf("0x%02x ",enhanced_bsk[i]);
	}
	printf("\n");
    return 0;
}

/******************************************************************************
 Descriptor:	test get onu_ver
 Input Args:	see gponmgr_root_command.
 Ret Value:	    FAIL:-1.
******************************************************************************/
static int do_get_onu_version(int argc,char * argv [ ],void * p)
{
	char onu_ver[OMCI_VERSION_LENS+END_OF_STRING] = {0};

	if(0!=omci_lib_get_onu_version(onu_ver,sizeof(onu_ver))){
		printf("call api error\n");
		return -1;
	}
	printf("onuVersion = %s\n",onu_ver);
    return 0;
}

/******************************************************************************
 Descriptor:	test get VendorId
 Input Args:	see gponmgr_root_command.
 Ret Value:	    FAIL:-1.
******************************************************************************/
static int do_get_vendor_id(int argc,char * argv [ ],void * p)
{
	char VendorId[OMCI_VENDOR_ID_LENS+END_OF_STRING]={0};

	if(0!=omci_lib_get_vendor_id(VendorId,sizeof(VendorId))){
		printf("call api error\n");
		return -1;
	}
	printf("vendorId = %s\n",VendorId);
    return 0;
}

/******************************************************************************
 Descriptor:	test get equipmentId
 Input Args:	see gponmgr_root_command.
 Ret Value:	    FAIL:-1.
******************************************************************************/
static int do_get_equipment_id(int argc,char * argv [ ],void * p)
{
	char equipmentId[OMCI_EQUIPMENTID_LENS+END_OF_STRING] = {0};

	if(0!=omci_lib_get_equipment_id(equipmentId,sizeof(equipmentId))){
		printf("call api error\n");
		return -1;
	}
	printf("equipmentId = %s\n",equipmentId);
    return 0;
}

/******************************************************************************
 Descriptor:	test get operatorID_cap
 Input Args:	see gponmgr_root_command.
 Ret Value:	    FAIL:-1.
******************************************************************************/
static int do_get_operator_id_cap(int argc,char * argv [ ],void * p)
{
	char operatorID_cap[OMCI_OPERATOR_ID_LENS+END_OF_STRING] = {0};

	if(0!=omci_lib_get_operator_id_cap(operatorID_cap,sizeof(operatorID_cap))){
		printf("call api error\n");
		return -1;
	}
	printf("opIdCap = %s\n",operatorID_cap);
    return 0;
}

/******************************************************************************
 Descriptor:	test get operatorID_auth
 Input Args:	see gponmgr_root_command.
 Ret Value:	    FAIL:-1.
******************************************************************************/
static int do_get_operator_id_auth(int argc,char * argv [ ],void * p)
{
	char operatorID_auth[OMCI_OPERATOR_ID_LENS+END_OF_STRING] = {0};

	if(0!=omci_lib_get_operator_id_auth(operatorID_auth,sizeof(operatorID_auth))){
		printf("call api error\n");
		return -1;
	}
	printf("opIdAuth = %s\n",operatorID_auth);
    return 0;
}

/******************************************************************************
 Descriptor:	test get LOID
 Input Args:	see gponmgr_root_command.
 Ret Value:	    FAIL:-1.
******************************************************************************/
static int do_get_loid(int argc,char * argv [ ],void * p)
{
	char Loid[OMCI_LOID_LENS+END_OF_STRING] = {0};

	if(0!=omci_lib_get_loid(Loid,sizeof(Loid))){
		printf("call api error\n");
		return -1;
	}
	printf("loid = %s\n",Loid);
    return 0;
}

/******************************************************************************
 Descriptor:	test get LOID_Password
 Input Args:	see gponmgr_root_command.
 Ret Value:	    FAIL:-1.
******************************************************************************/
static int do_get_loid_password(int argc,char * argv [ ],void * p)
{
	char LOID_Password[OMCI_LOID_PASSWORD_LENS+END_OF_STRING] = {0};

	if(0!=omci_lib_get_loid_password(LOID_Password,sizeof(LOID_Password))){
		printf("call api error\n");
		return -1;
	}
	printf("loidPasswd = %s\n",LOID_Password);
    return 0;
}

/******************************************************************************
 Descriptor:	test get linkMode
 Input Args:	see gponmgr_root_command.
 Ret Value:	    FAIL:-1.
******************************************************************************/
static int do_get_link_mode(int argc,char * argv [ ],void * p)
{
	int linkMode;

	if(0!=omci_lib_get_link_mode((onu_link_mode_t *)&linkMode)){
		printf("call api error\n");
		return -1;
	}
	printf("linkMode = %d\n",linkMode);
    return 0;
}

/******************************************************************************
 Descriptor:	test get vendorProCode
 Input Args:	see gponmgr_root_command.
 Ret Value:	    FAIL:-1.
******************************************************************************/
static int do_get_vendor_pro_code(int argc,char * argv [ ],void * p)
{
	unsigned short vendorProCode;

	if(0!=omci_lib_get_vendor_pro_code(&vendorProCode)){
		printf("call api error\n");
		return -1;
	}
	printf("vendorProCode = %d\n",vendorProCode);
    return 0;
}

/******************************************************************************
 Descriptor:	test get omccVersion
 Input Args:	see gponmgr_root_command.
 Ret Value:	    FAIL:-1.
******************************************************************************/
static int do_get_omcc_version(int argc,char * argv [ ],void * p)
{
	unsigned char omccVersion;

	if(0!=omci_lib_get_omcc_version(&omccVersion)){
		printf("call api error\n");
		return -1;
	}
	printf("omccVersion = 0x%x\n",omccVersion);
    return 0;
}

/******************************************************************************
 Descriptor:	test get tmOption
 Input Args:	see gponmgr_root_command.
 Ret Value:	    FAIL:-1.
******************************************************************************/
static int do_get_tm_option(int argc,char * argv [ ],void * p)
{
	unsigned char tmOption;

	if(0!=omci_lib_get_tm_option(&tmOption)){
		printf("call api error\n");
		return -1;
	}
	printf("tmOption = %d\n",tmOption);
    return 0;
}
/******************************************************************************
 Descriptor:	test get onuSurvivalTime
 Input Args:	see gponmgr_root_command.
 Ret Value:	    FAIL:-1.
******************************************************************************/
static int do_get_survival_time(int argc,char * argv [ ],void * p)
{
	unsigned char onuSurvivalTime;

	if(0!=omci_lib_get_survival_time(&onuSurvivalTime)){
		printf("call api error\n");
		return -1;
	}
	printf("onuSurvivalTime = %d\n",onuSurvivalTime);
    return 0;
}
/******************************************************************************
 Descriptor:	test get extendedTcLayer
 Input Args:	see gponmgr_root_command.
 Ret Value:	    FAIL:-1.
******************************************************************************/
static int do_get_extended_tclayer(int argc,char * argv [ ],void * p)
{
	unsigned char extendedTcLayer;

	if(0!=omci_lib_get_extended_tclayer(&extendedTcLayer)){
		printf("call api error\n");
		return -1;
	}
	printf("extendedTcLayer = %d\n",extendedTcLayer);
    return 0;
}
/******************************************************************************
 Descriptor:	test get securityCap
 Input Args:	see gponmgr_root_command.
 Ret Value:	    FAIL:-1.
******************************************************************************/
static int do_get_security_cap(int argc,char * argv [ ],void * p)
{
	unsigned char securityCap;

	if(0!=omci_lib_get_security_cap(&securityCap)){
		printf("call api error\n");
		return -1;
	}
	printf("securityCap = 0x%x\n",securityCap);
    return 0;
}
/******************************************************************************
 Descriptor:	test get totalTSNum
 Input Args:	see gponmgr_root_command.
 Ret Value:	    FAIL:-1.
******************************************************************************/
static int do_get_total_ts_num(int argc,char * argv [ ],void * p)
{
	unsigned char totalTSNum;

	if(0!=omci_lib_get_total_ts_num(&totalTSNum)){
		printf("call api error\n");
		return -1;
	}
	printf("totalTSNum = %d\n",totalTSNum);
    return 0;
}

/******************************************************************************
 Descriptor:	test get totalPQNum
 Input Args:	see gponmgr_root_command.
 Ret Value:	    FAIL:-1.
******************************************************************************/
static int do_get_total_pq_num(int argc,char * argv [ ],void * p)
{
	unsigned short totalPQNum;

	if(0!=omci_lib_get_total_pq_num(&totalPQNum)){
		printf("call api error\n");
		return -1;
	}
	printf("totalPQNum = %d\n",totalPQNum);
    return 0;
}

/******************************************************************************
 Descriptor:	test get totalGEMPortNum
 Input Args:	see gponmgr_root_command.
 Ret Value:	    FAIL:-1.
******************************************************************************/
static int do_get_total_gemport_num(int argc,char * argv [ ],void * p)
{
	unsigned short totalGEMPortNum;

	if(0!=omci_lib_get_total_gemport_num(&totalGEMPortNum)){
		printf("call api error\n");
		return -1;
	}
	printf("totalGEMPortNum = %d\n",totalGEMPortNum);
    return 0;
}

/******************************************************************************
 Descriptor:	test get connectivityCap
 Input Args:	see gponmgr_root_command.
 Ret Value:	    FAIL:-1.
******************************************************************************/
static int do_get_connectivity_cap(int argc,char * argv [ ],void * p)
{
	unsigned short connectivityCap;

	if(0!=omci_lib_get_connectivity_cap(&connectivityCap)){
		printf("call api error\n");
		return -1;
	}
	printf("connectivityCap = 0x%x\n",connectivityCap);
    return 0;
}

/******************************************************************************
 Descriptor:	test get qoSConfFlex
 Input Args:	see gponmgr_root_command.
 Ret Value:	    FAIL:-1.
******************************************************************************/
static int do_get_qos_conf_flex(int argc,char * argv [ ],void * p)
{
	unsigned short qoSConfFlex;

	if(0!=omci_lib_get_qos_conf_flex(&qoSConfFlex)){
		printf("call api error\n");
		return -1;
	}
	printf("qosConfFlex = 0x%x\n",qoSConfFlex);
    return 0;
}

/******************************************************************************
 Descriptor:	test get VoIPbyTR069
 Input Args:	see gponmgr_root_command.
 Ret Value:	    FAIL:-1.
******************************************************************************/
static int do_get_voip_by_tr069(int argc,char * argv [ ],void * p)
{
	char VoIPbyTR069;

	if(0!=omci_lib_get_voip_by_tr069(&VoIPbyTR069)){
		printf("call api error\n");
		return -1;
	}
	printf("voipByTr069 = %d\n",VoIPbyTR069);
    return 0;
}

/******************************************************************************
 Descriptor:	test get VoIPbyTR069
 Input Args:	see gponmgr_root_command.
 Ret Value:	    FAIL:-1.
******************************************************************************/
static int do_get_voip_sep_en(int argc,char * argv [ ],void * p)
{
	char VoIPSepEn;

	if(0!=omci_lib_get_voip_sep_en(&VoIPSepEn)){
		printf("call api error\n");
		return -1;
	}
	printf("VoIPSepEn = %d\n",VoIPSepEn);
    return 0;
}

/******************************************************************************
 Descriptor:	test get SpecVersion
 Input Args:	see gponmgr_root_command.
 Ret Value:	    FAIL:-1.
******************************************************************************/
static int do_get_spec_version(int argc,char * argv [ ],void * p)
{
	unsigned char SpecVersion;

	if(0!=omci_lib_get_spec_version(&SpecVersion)){
		printf("call api error\n");
		return -1;
	}
	printf("SpecVersion = %d\n",SpecVersion);
    return 0;
}
/******************************************************************************
 Descriptor:	test get ONU_PowerCtr
 Input Args:	see gponmgr_root_command.
 Ret Value:	    FAIL:-1.
******************************************************************************/
static int do_get_onu_power_ctrl(int argc,char * argv [ ],void * p)
{
	unsigned char ONU_PowerCtr;

	if(0!=omci_lib_get_onu_power_ctrl(&ONU_PowerCtr)){
		printf("call api error\n");
		return -1;
	}
	printf("onuPowerCtr = %d\n",ONU_PowerCtr);
    return 0;
}

/******************************************************************************
 Descriptor:	test get AuthStatus
 Input Args:	see gponmgr_root_command.
 Ret Value:	    FAIL:-1.
******************************************************************************/
static int do_get_auth_status(int argc,char * argv [ ],void * p)
{
	unsigned char AuthStatus;

	if(0!=omci_lib_get_auth_status(&AuthStatus)){
		printf("call api error\n");
		return -1;
	}
	printf("authStat = %d\n",AuthStatus);
    return 0;
}

/******************************************************************************
 Descriptor:	test get srIndication
 Input Args:	see gponmgr_root_command.
 Ret Value:	    FAIL:-1.
******************************************************************************/
static int do_get_sr_indication(int argc,char * argv [ ],void * p)
{
	unsigned char srIndication;

	if(0!=omci_lib_get_sr_indication(&srIndication)){
		printf("call api error\n");
		return -1;
	}
	printf("srIndication = %d\n",srIndication);
    return 0;
}

/******************************************************************************
 Descriptor:	test get totalTcontNum
 Input Args:	see gponmgr_root_command.
 Ret Value:	    FAIL:-1.
******************************************************************************/
static int do_get_total_tcont_num(int argc,char * argv [ ],void * p)
{
	unsigned short totalTcontNum;

	if(0!=omci_lib_get_total_tcont_num(&totalTcontNum)){
		printf("call api error\n");
		return -1;
	}
	printf("totalTcontNum = %d\n",totalTcontNum);
    return 0;
}

/******************************************************************************
 Descriptor:	test get gemBlockLength
 Input Args:	see gponmgr_root_command.
 Ret Value:	    FAIL:-1.
******************************************************************************/
static int do_get_gem_block_length(int argc,char * argv [ ],void * p)
{
	unsigned short gemBlockLength;

	if(0!=omci_lib_get_gem_block_length(&gemBlockLength)){
		printf("call api error\n");
		return -1;
	}
	printf("gemBlockLength = %d\n",gemBlockLength);
    return 0;
}

/******************************************************************************
 Descriptor:	test get onuResponseTime
 Input Args:	see gponmgr_root_command.
 Ret Value:	    FAIL:-1.
******************************************************************************/
static int do_get_onu_response_time(int argc,char * argv [ ],void * p)
{
	unsigned short onuResponseTime;

	if(0!=omci_lib_get_onu_response_time(&onuResponseTime)){
		printf("call api error\n");
		return -1;
	}
	printf("onuResponseTime = %d\n",onuResponseTime);
    return 0;
}


/******************************************************************************
 Descriptor:	test get conReqPort
 Input Args:	see gponmgr_root_command.
 Ret Value:	    FAIL:-1.
******************************************************************************/
static int do_get_con_req_port(int argc,char * argv [ ],void * p)
{
	unsigned short conReqPort;

	if(0!=omci_lib_get_con_req_port(&conReqPort)){
		printf("call api error\n");
		return -1;
	}
	printf("conReqPort = %d\n",conReqPort);
    return 0;
}

/******************************************************************************
 Descriptor:	test get port id
 Input Args:	see gponmgr_root_command.
 Ret Value:	    FAIL:-1.
******************************************************************************/
static int do_get_max_ports_list(int argc,char * argv [ ],void * p)
{
	int * port_id = NULL;
	signed char allPortsNum = 0;
	int i;
	omci_lib_get_max_ports(&allPortsNum);
	printf("allPortsNum = %d\n",allPortsNum);

	port_id = (int *)(malloc(sizeof(int)*allPortsNum));

	if(port_id != NULL)
	{
		if(0!=omci_lib_get_port_list(port_id)){
			printf("call api error\n");
			free(port_id);
			return -1;
		}
		
		for (i = 0; i < allPortsNum; i++)
		{
			printf("port_id[%d] = %d\n",i,port_id[i]);
		}
		free(port_id);
	}else{
		printf("get port list fail!\n");
	}
    return 0;
}

/******************************************************************************
 Descriptor:	It's used to set serialnumber
 Input Args:	see gponmgr_set_command.
 Ret Value:	success: 0
                       fail: -1
******************************************************************************/
static int do_set_sn(int argc, char *argv[], void *p)
{
    unsigned char sn[OMCI_SN_MEM_LENS]={0} ;
	if(strlen(argv[1]) == 12) {
		strncpy((char *)sn, argv[1], 12);		
	    if(-1==omci_lib_set_sn_mem(sn))
	    {
	        printf("Exec. Failed\n");
			return -1;
	    }
	}else{
		printf("Exec. Failed, invalid length \n");
		return -1;
	}
    printf("Exec. Successful\n");
    return 0;

}

/******************************************************************************
 Descriptor:	It's used to set GPON password with 0~10 ASCII words.
 Input Args:	see gponmgr_set_passwd_command.
 Ret Value:	success: 0
                       fail: -1
******************************************************************************/
static int do_set_passwd_ascii(int argc, char *argv[], void *p)
{
	char passwd[OMCI_REG_ID_LENS+1] = {0};
	strncpy(passwd, argv[1], OMCI_REG_ID_LENS);
	
    if(-1==omci_lib_set_passwd_mem(passwd))
    {
        printf("Exec. Failed\n");
        return -1;
    }
    printf("Exec. Successful\n");
    return 0;
	
}

/******************************************************************************
 Descriptor:	It's used to set GPON password with 0~20 hexadecimal.
 Input Args:	see gponmgr_set_passwd_command.
 Ret Value:	success: 0
                       fail: -1
******************************************************************************/
static int do_set_passwd_hex(int argc, char *argv[], void *p)
{
    char passwd[OMCI_REG_ID_LENS] ;
	int len, i;
	char tmp[3];
	memset(passwd, 0, sizeof(passwd)) ;
	len = strlen(argv[1]);
	/* hexadecimal length is twice as big as ASCII length  */
	if(len <= (OMCI_PASSWD_LENS << 1)) {
		tmp[2] = '\0';
		for(i = 0; i < (len >> 1); i++) {
			tmp[0] = argv[1][i * 2];
			tmp[1] = argv[1][i * 2 + 1];
			passwd[i] = (unsigned char)strtoul(tmp, NULL, 16);
		}
		/* len is odd number */
		if((len % 2) && (i < OMCI_PASSWD_LENS)) {
			tmp[0] = argv[1][i * 2];
			tmp[1] = '0';
			passwd[i] = (unsigned char)strtoul(tmp, NULL, 16);
		}
	} else {
		printf("Input Error: password length must be less than %d hexadecimal digits.\n", OMCI_PASSWD_LENS << 1) ;
		return -1;
	}

	if(-1==omci_lib_set_passwd_mem(passwd)) {
		printf("Exec. Failed: Set the 'passwd' command failed\n") ;
		return -1;
	}
	printf("Exec. Successful\n") ;
	return 0;
}

/******************************************************************************
 Descriptor:	It's used to set OMCI dbg level.
 Input Args:	see gponmgr_set_command.
 Ret Value:	success: 0
                       fail: -1
******************************************************************************/
static int do_set_omci_dbg_level(int argc, char *argv[], void *p)
{
    unsigned char DebugLevel = atoi(argv[1]);
    if(-1==omci_lib_set_omci_dbg_level(DebugLevel))
    {
        printf("Exec. Failed\n");
        return -1;
    }
    printf("Exec. Successful\n");
    return 0;
}

/******************************************************************************
 Descriptor:	It's used to set lan_debug.
 Input Args:	see gponmgr_set_command.
 Ret Value:	success: 0
                       fail: -1
******************************************************************************/
static int do_set_lan_debug(int argc, char *argv[], void *p)
{
    unsigned char lan_debug = atoi(argv[1]);
    if(-1==omci_lib_set_lan_debug(lan_debug))
    {
        printf("Exec. Failed\n");
        return -1;
    }
    printf("Exec. Successful\n");
    return 0;
}

/******************************************************************************
 Descriptor:	It's used to set enhanced_psk.
 Input Args:	see gponmgr_set_command.
 Ret Value:	success: 0
                       fail: -1
******************************************************************************/
static int do_set_enhanced_psk(int argc, char *argv[], void *p)
{
	char buffer[52];
	int tmpPSK[PRESHARED_KEY_LEN] = {0};
	unsigned char enhanced_bsk[PRESHARED_KEY_LEN] = {0};
	int i;
	memcpy(buffer,argv[1],sizeof(buffer));
	sscanf(buffer, "%02X,%02X,%02X,%02X,%02X,%02X,%02X,%02X,%02X,%02X,%02X,%02X,%02X,%02X,%02X,%02X", 
		&tmpPSK[0], &tmpPSK[1], &tmpPSK[2], &tmpPSK[3], &tmpPSK[4], &tmpPSK[5], &tmpPSK[6], &tmpPSK[7], 
		&tmpPSK[8], &tmpPSK[9], &tmpPSK[10], &tmpPSK[11], &tmpPSK[12], &tmpPSK[13], &tmpPSK[14], &tmpPSK[15]);
	for(i=0; i<PRESHARED_KEY_LEN; i++){
		if((tmpPSK[i] >= 0) && (tmpPSK[i] <= 255))
			enhanced_bsk[i] = tmpPSK[i];
		else{
			printf("Invalid PSK value\n");
			return -1;
		}
	}
    if(-1==omci_lib_set_enhanced_psk(enhanced_bsk))
    {
        printf("Exec. Failed\n");
        return -1;
    }
    printf("Exec. Successful\n");
    return 0;
}

/******************************************************************************
 Descriptor:	It's used to set onu_version.
 Input Args:	see gponmgr_set_command.
 Ret Value:	success: 0
                       fail: -1
******************************************************************************/
static int do_set_onu_version(int argc, char *argv[], void *p)
{
	char onu_version[OMCI_VERSION_LENS+1]= {0};
	strncpy(onu_version, argv[1], OMCI_VERSION_LENS);
    if(-1==omci_lib_set_onu_version(onu_version))
    {
        printf("Exec. Failed\n");
        return -1;
    }
    printf("Exec. Successful\n");
    return 0;
}

/******************************************************************************
 Descriptor:	It's used to set VendorId.
 Input Args:	see gponmgr_set_command.
 Ret Value:	success: 0
                       fail: -1
******************************************************************************/
static int do_set_vendor_id(int argc, char *argv[], void *p)
{
	char VendorId[OMCI_VENDOR_ID_LENS+1] = {0};
	strncpy(VendorId, argv[1], OMCI_VENDOR_ID_LENS);
    if(-1==omci_lib_set_vendor_id(VendorId))
    {
        printf("Exec. Failed\n");
        return -1;
    }
    printf("Exec. Successful\n");
    return 0;
}

/******************************************************************************
 Descriptor:	It's used to set equipmentId.
 Input Args:	see gponmgr_set_command.
 Ret Value:	success: 0
                       fail: -1
******************************************************************************/
static int do_set_equipment_id(int argc, char *argv[], void *p)
{
	char equipmentId[OMCI_EQUIPMENTID_LENS+1] = {0};
	strncpy(equipmentId, argv[1], OMCI_EQUIPMENTID_LENS);
    if(-1==omci_lib_set_equipment_id(equipmentId))
    {
        printf("Exec. Failed\n");
        return -1;
    }
    printf("Exec. Successful\n");
    return 0;
}

/******************************************************************************
 Descriptor:	It's used to set operatorID_cap.
 Input Args:	see gponmgr_set_command.
 Ret Value:	success: 0
                       fail: -1
******************************************************************************/
static int do_set_operator_id_cap(int argc, char *argv[], void *p)
{
	char operatorID_cap[OMCI_OPERATOR_ID_LENS+1] = {0};
	strncpy(operatorID_cap, argv[1], OMCI_OPERATOR_ID_LENS);
    if(-1==omci_lib_set_operator_id_cap(operatorID_cap))
    {
        printf("Exec. Failed\n");
        return -1;
    }
    printf("Exec. Successful\n");
    return 0;
}

/******************************************************************************
 Descriptor:	It's used to set operatorID_auth.
 Input Args:	see gponmgr_set_command.
 Ret Value:	success: 0
                       fail: -1
******************************************************************************/
static int do_set_operator_id_auth(int argc, char *argv[], void *p)
{
	char operatorID_auth[OMCI_OPERATOR_ID_LENS+1] = {0};
	strncpy(operatorID_auth, argv[1], OMCI_OPERATOR_ID_LENS);
    if(-1==omci_lib_set_operator_id_auth(operatorID_auth))
    {
        printf("Exec. Failed\n");
        return -1;
    }
    printf("Exec. Successful\n");
    return 0;
}

/******************************************************************************
 Descriptor:	It's used to set LOID.
 Input Args:	see gponmgr_set_command.
 Ret Value:	success: 0
                       fail: -1
******************************************************************************/
static int do_set_loid(int argc, char *argv[], void *p)
{
	char Loid[OMCI_LOID_LENS+1] = {0};
	strncpy(Loid, argv[1], OMCI_LOID_LENS);
	
    if(-1==omci_lib_set_loid(Loid))
    {
        printf("Exec. Failed\n");
        return -1;
    }
    printf("Exec. Successful\n");
    return 0;
}
/******************************************************************************
 Descriptor:	It's used to set LOID_Password.
 Input Args:	see gponmgr_set_command.
 Ret Value:	success: 0
                       fail: -1
******************************************************************************/
static int do_set_loid_password(int argc, char *argv[], void *p)
{
	char LOID_Password[OMCI_LOID_PASSWORD_LENS+1] = {0};
	strncpy(LOID_Password, argv[1], OMCI_LOID_PASSWORD_LENS);
	
    if(-1==omci_lib_set_loid_password(LOID_Password))
    {
        printf("Exec. Failed\n");
        return -1;
    }
    printf("Exec. Successful\n");
    return 0;
}

/******************************************************************************
 Descriptor:	It's used to set linkMode.
 Input Args:	see gponmgr_set_command.
 Ret Value:	success: 0
                       fail: -1
******************************************************************************/
static int do_set_link_mode(int argc, char *argv[], void *p)
{
    char linkMode = atoi(argv[1]);
    if(-1==omci_lib_set_link_mode(linkMode))
    {
        printf("Exec. Failed\n");
        return -1;
    }
    printf("Exec. Successful\n");
    return 0;
}

/******************************************************************************
 Descriptor:	It's used to set vendorProCode.
 Input Args:	see gponmgr_set_command.
 Ret Value:	success: 0
                       fail: -1
******************************************************************************/
static int do_set_vendor_pro_code(int argc, char *argv[], void *p)
{
    unsigned short vendorProCode = atoi(argv[1]);
    if(-1==omci_lib_set_vendor_pro_code(vendorProCode))
    {
        printf("Exec. Failed\n");
        return -1;
    }
    printf("Exec. Successful\n");
    return 0;
}

/******************************************************************************
 Descriptor:	It's used to set omccVersion.
 Input Args:	see gponmgr_set_command.
 Ret Value:	success: 0
                       fail: -1
******************************************************************************/
static int do_set_omcc_version(int argc, char *argv[], void *p)
{
    unsigned char omccVersion = (unsigned char)strtol(argv[1], (char**)NULL, 16);
    if(-1==omci_lib_set_omcc_version(omccVersion))
    {
        printf("Exec. Failed\n");
        return -1;
    }
    printf("Exec. Successful\n");
    return 0;
}

/******************************************************************************
 Descriptor:	It's used to set tmOption.
 Input Args:	see gponmgr_set_command.
 Ret Value:	success: 0
                       fail: -1
******************************************************************************/
static int do_set_tm_option(int argc, char *argv[], void *p)
{
    unsigned char tmOption = atoi(argv[1]);
    if(-1==omci_lib_set_tm_option(tmOption))
    {
        printf("Exec. Failed\n");
        return -1;
    }
    printf("Exec. Successful\n");
    return 0;
}

/******************************************************************************
 Descriptor:	It's used to set onuSurvivalTime.
 Input Args:	see gponmgr_set_command.
 Ret Value:	success: 0
                       fail: -1
******************************************************************************/
static int do_set_survival_time(int argc, char *argv[], void *p)
{
    unsigned char onuSurvivalTime = atoi(argv[1]);
    if(-1==omci_lib_set_survival_time(onuSurvivalTime))
    {
        printf("Exec. Failed\n");
        return -1;
    }
    printf("Exec. Successful\n");
    return 0;
}

/******************************************************************************
 Descriptor:	It's used to set extendedTcLayer.
 Input Args:	see gponmgr_set_command.
 Ret Value:	success: 0
                       fail: -1
******************************************************************************/
static int do_set_extended_tclayer(int argc, char *argv[], void *p)
{
    unsigned char extendedTcLayer = atoi(argv[1]);
    if(-1==omci_lib_set_extended_tclayer(extendedTcLayer))
    {
        printf("Exec. Failed\n");
        return -1;
    }
    printf("Exec. Successful\n");
    return 0;
}

/******************************************************************************
 Descriptor:	It's used to set securityCap.
 Input Args:	see gponmgr_set_command.
 Ret Value:	success: 0
                       fail: -1
******************************************************************************/
static int do_set_security_cap(int argc, char *argv[], void *p)
{
    unsigned char securityCap = (unsigned char)strtol(argv[1], (char**)NULL, 16);
    if(-1==omci_lib_set_security_cap(securityCap))
    {
        printf("Exec. Failed\n");
        return -1;
    }
    printf("Exec. Successful\n");
    return 0;
}

/******************************************************************************
 Descriptor:	It's used to set totalTSNum.
 Input Args:	see gponmgr_set_command.
 Ret Value:	success: 0
                       fail: -1
******************************************************************************/
static int do_set_total_ts_num(int argc, char *argv[], void *p)
{
    unsigned char totalTSNum = atoi(argv[1]);
    if(-1==omci_lib_set_total_ts_num(totalTSNum))
    {
        printf("Exec. Failed\n");
        return -1;
    }
    printf("Exec. Successful\n");
    return 0;
}

/******************************************************************************
 Descriptor:	It's used to set totalPQNum.
 Input Args:	see gponmgr_set_command.
 Ret Value:	success: 0
                       fail: -1
******************************************************************************/
static int do_set_total_pq_num(int argc, char *argv[], void *p)
{
    unsigned short totalPQNum = atoi(argv[1]);
    if(-1==omci_lib_set_total_pq_num(totalPQNum))
    {
        printf("Exec. Failed\n");
        return -1;
    }
    printf("Exec. Successful\n");
    return 0;
}

/******************************************************************************
 Descriptor:	It's used to set totalGEMPortNum.
 Input Args:	see gponmgr_set_command.
 Ret Value:	success: 0
                       fail: -1
******************************************************************************/
static int do_set_total_gemport_num(int argc, char *argv[], void *p)
{
    unsigned short totalGEMPortNum = atoi(argv[1]);
    if(-1==omci_lib_set_total_gemport_num(totalGEMPortNum))
    {
        printf("Exec. Failed\n");
        return -1;
    }
    printf("Exec. Successful\n");
    return 0;
}

/******************************************************************************
 Descriptor:	It's used to set securityCap.
 Input Args:	see gponmgr_set_command.
 Ret Value:	success: 0
                       fail: -1
******************************************************************************/
static int do_set_connectivity_cap(int argc, char *argv[], void *p)
{
    unsigned short connectivityCap =(unsigned short)strtol(argv[1], (char**)NULL, 16);
    if(-1==omci_lib_set_connectivity_cap(connectivityCap))
    {
        printf("Exec. Failed\n");
        return -1;
    }
    printf("Exec. Successful\n");
    return 0;
}

/******************************************************************************
 Descriptor:	It's used to set qoSConfFlex.
 Input Args:	see gponmgr_set_command.
 Ret Value:	success: 0
                       fail: -1
******************************************************************************/
static int do_set_qos_conf_flex(int argc, char *argv[], void *p)
{
    unsigned short qoSConfFlex =(unsigned short)strtol(argv[1], (char**)NULL, 16);
    if(-1==omci_lib_set_qos_conf_flex(qoSConfFlex))
    {
        printf("Exec. Failed\n");
        return -1;
    }
    printf("Exec. Successful\n");
    return 0;
}

/******************************************************************************
 Descriptor:	It's used to set VoIPbyTR069.
 Input Args:	see gponmgr_set_command.
 Ret Value:	success: 0
                       fail: -1
******************************************************************************/
static int do_set_voip_by_tr069(int argc, char *argv[], void *p)
{
    char VoIPbyTR069 = atoi(argv[1]);
    if(-1==omci_lib_set_voip_by_tr069(VoIPbyTR069))
    {
        printf("Exec. Failed\n");
        return -1;
    }
    printf("Exec. Successful\n");
    return 0;
}

/******************************************************************************
 Descriptor:	It's used to set VoIP time separate enable.
 Input Args:	see gponmgr_set_command.
 Ret Value:	success: 0
                       fail: -1
******************************************************************************/
static int do_set_voip_sep_en(int argc, char *argv[], void *p)
{
    char VoIPSepEn = atoi(argv[1]);
    if(-1==omci_lib_set_voip_sep_en(VoIPSepEn))
    {
        printf("Exec. Failed\n");
        return -1;
    }
    printf("Exec. Successful\n");
    return 0;
}

/******************************************************************************
 Descriptor:	It's used to set SpecVersion.
 Input Args:	see gponmgr_set_command.
 Ret Value:	success: 0
                       fail: -1
******************************************************************************/
static int do_set_spec_version(int argc, char *argv[], void *p)
{
    unsigned char SpecVersion = atoi(argv[1]);
    if(-1==omci_lib_set_spec_version(SpecVersion))
    {
        printf("Exec. Failed\n");
        return -1;
    }
    printf("Exec. Successful\n");
    return 0;
}

/******************************************************************************
 Descriptor:	It's used to set ONU_PowerCtr.
 Input Args:	see gponmgr_set_command.
 Ret Value:	success: 0
                       fail: -1
******************************************************************************/
static int do_set_onu_power_ctrl(int argc, char *argv[], void *p)
{
    unsigned char ONU_PowerCtr = atoi(argv[1]);
    if(-1==omci_lib_set_onu_power_ctrl(ONU_PowerCtr))
    {
        printf("Exec. Failed\n");
        return -1;
    }
    printf("Exec. Successful\n");
    return 0;
}

/******************************************************************************
 Descriptor:	It's used to set AuthStatus.
 Input Args:	see gponmgr_set_command.
 Ret Value:	success: 0
                       fail: -1
******************************************************************************/
static int do_set_auth_status(int argc, char *argv[], void *p)
{
    unsigned char AuthStatus = atoi(argv[1]);
    if(-1==omci_lib_set_auth_status(AuthStatus))
    {
        printf("Exec. Failed\n");
        return -1;
    }
    printf("Exec. Successful\n");
    return 0;
}

/******************************************************************************
 Descriptor:	It's used to set srIndication.
 Input Args:	see gponmgr_set_command.
 Ret Value:	success: 0
                       fail: -1
******************************************************************************/
static int do_set_sr_indication(int argc, char *argv[], void *p)
{
    unsigned char srIndication = atoi(argv[1]);
    if(-1==omci_lib_set_sr_indication(srIndication))
    {
        printf("Exec. Failed\n");
        return -1;
    }
    printf("Exec. Successful\n");
    return 0;
}

/******************************************************************************
 Descriptor:	It's used to set totalTcontNum.
 Input Args:	see gponmgr_set_command.
 Ret Value:	success: 0
                       fail: -1
******************************************************************************/
static int do_set_total_tcont_num(int argc, char *argv[], void *p)
{
    unsigned short totalTcontNum = atoi(argv[1]);
    if(-1==omci_lib_set_total_tcont_num(totalTcontNum))
    {
        printf("Exec. Failed\n");
        return -1;
    }
    printf("Exec. Successful\n");
    return 0;
}

/******************************************************************************
 Descriptor:	It's used to set gemBlockLength.
 Input Args:	see gponmgr_set_command.
 Ret Value:	success: 0
                       fail: -1
******************************************************************************/
static int do_set_gem_block_length(int argc, char *argv[], void *p)
{
    unsigned short gemBlockLength = atoi(argv[1]);
    if(-1==omci_lib_set_gem_block_length(gemBlockLength))
    {
        printf("Exec. Failed\n");
        return -1;
    }
    printf("Exec. Successful\n");
    return 0;
}

/******************************************************************************
 Descriptor:	It's used to set onuResponseTime.
 Input Args:	see gponmgr_set_command.
 Ret Value:	success: 0
                       fail: -1
******************************************************************************/
static int do_set_onu_response_time(int argc, char *argv[], void *p)
{
    unsigned short onuResponseTime = atoi(argv[1]);
    if(-1==omci_lib_set_onu_response_time(onuResponseTime))
    {
        printf("Exec. Failed\n");
        return -1;
    }
    printf("Exec. Successful\n");
    return 0;
}

/******************************************************************************
 Descriptor:	It's used to set conReqPort.
 Input Args:	see gponmgr_set_command.
 Ret Value:	success: 0
                       fail: -1
******************************************************************************/
static int do_set_con_req_port(int argc, char *argv[], void *p)
{
    unsigned short conReqPort = atoi(argv[1]);
    if(-1==omci_lib_set_con_req_port(conReqPort))
    {
        printf("Exec. Failed\n");
        return -1;
    }
    printf("Exec. Successful\n");
    return 0;
}

/******************************************************************************
 Descriptor:	It's used to set portId.
 Input Args:	see gponmgr_set_command.
 Ret Value:	success: 0
                       fail: -1
******************************************************************************/
static int do_set_max_ports_list(int argc, char *argv[], void *p)
{
	int portId[OMCI_MAX_PORTS] = {0};
	char buffer[OMCI_MAX_PORTS*4] = {0};
	char tempbuf[64] = {0};
	char *pbuffer =buffer;
	char *getstr = NULL;
	signed char allPortsNum = 0;
	int i = 0;
	int str_len = 0;
	
	allPortsNum = (unsigned char)atoi(argv[1]);
	if(allPortsNum <= 0)
	{
        printf("Invalid allPortsNum\n");
        return -1;
	}
	str_len = (strlen(argv[2]) < OMCI_MAX_PORTS*4) ? strlen(argv[2]):(OMCI_MAX_PORTS*4-1);
	memcpy(buffer,argv[2],str_len);
	
	for(i = 0; i < allPortsNum-1; i++)
	{
		if((getstr = strchr(pbuffer,',')) == NULL)
			break;
		memset(tempbuf,0,64);
		strncpy(tempbuf,pbuffer,(getstr - pbuffer));
		portId[i]=atoi(tempbuf);
		printf("portId[%d] = %d\n",i,portId[i]);
		pbuffer = getstr + 1;
	}
	if(i != allPortsNum-1)
	{
        printf("Port ID number is not enough!\n");
        return -1;	
	}
	/*The last port ID*/
	portId[i]=atoi(pbuffer);
	printf("portId[%d] = %d\n",i,portId[i]);

    if(-1==omci_lib_set_max_ports_list(allPortsNum,portId))
    {
        printf("Exec. Failed\n");
        return -1;
    }
    printf("Exec. Successful\n");
    return 0;
}

static int do_get_pon_trap_thread(int argc, char *argv[], void *p)
{
    int ponTrapThread = 0;

    if(0 != omci_lib_get_pon_trap_thread(&ponTrapThread)){
		printf("call api error\n");
        return -1;
    }
	printf("ponTrapThread = %d\n",ponTrapThread);
	return 0;	
}

static int do_set_pon_trap_thread(int argc, char *argv[], void *p)
{
    int ponTrapThread = atoi(argv[1]);
	
    printf("[%s][%d]set pon trap thread = %d\n", __FUNCTION__, __LINE__, ponTrapThread);
    if(0 != omci_lib_set_pon_trap_thread(ponTrapThread)){
        printf("[%s][%d]Exec. Failed\n", __FUNCTION__, __LINE__);
        return -1;
    }
	printf("Exec. Successful\n") ;
	return 0;	
}

